<script>
import { dictMixin } from '@/mixin/dict'

export default {
  name: 'OperateProductModel',
  mixins: [dictMixin],
  props: {
    // 弹窗数据
    popData: {
      type: Object,
      default: () => ({})
    },
    // 弹窗配置
    popConfig: {
      type: Object,
      default: () => ({})
    },
    // 弹窗取消
    close: {
      type: Boolean,
      default: false
    },
    // 弹窗确认
    confirm: {
      type: Boolean,
      default: false
    }
  },
  created() {
    if (this.popData.modelIdArray.length > 0) {
      this.loadingDetailIds(this.popData.modelIdArray)
    }
  },
  data() {
    return {
      list: [],
      loading: false
    }
  },
  methods: {
    async loadingDetailIds(ids) {
      this.loading = true
      const res = await this.$api.physicalModel.detailByIds(ids)
      this.list = res.data
      this.loading = false
    }
  }
}
</script>

<template>
  <div>
    <el-table :data="list" v-loading="loading">
      <el-table-column prop="modelName" label="名称" width="140"/>
      <el-table-column prop="modelTag" label="标识符" />
      <el-table-column prop="realTimeMonitor" label="实时监测">
        <template #default="{row}">
          {{ row.modelFeatures.split(',').includes('1') ? '是' : '否' }}
        </template>
      </el-table-column>
      <el-table-column prop="readOnly" label="只读">
        <template #default="{row}">
          {{ row.modelFeatures.split(',').includes('2') ? '是' : '否' }}
        </template>
      </el-table-column>
      <el-table-column prop="historyStore" label="历史存储">
        <template #default="{row}">
          {{ row.modelFeatures.split(',').includes('3') ? '是' : '否' }}
        </template>
      </el-table-column>
      <el-table-column prop="modelTypeName" label="物模型类别" />
      <el-table-column prop="fieldTypeName" label="数据类型" />
      <el-table-column prop="dataExt" label="数据定义" width="220">
        <template #default="{row}">
          <div>
            <template v-if="row.fieldType === '1' || row.fieldType === '2'">
              <div v-if="row.dataType === '1'">
                <div style="display: inline-flex">
                  <span style="width: 100px">最大值：<span style="color: red">{{ row.dataExtMap.maxValue }}</span></span>
                  <span>最小值：<span style="color: red">{{ row.dataExtMap.minValue }}</span></span>
                </div>
                <div style="display: inline-flex">
                  <span style="width: 100px">步长：<span style="color: red">{{ row.dataExtMap.step }}</span></span>
                  <span>单位：<span style="color: red">{{ row.dataExtMap.unit }}</span></span>
                </div>
              </div>
              <div v-else>
                <div style="display: inline-flex">
                  <span style="width: 100px">额定值：<span style="color: red">{{ row.dataExtMap.fixedValue }}</span></span>
                  <span>单位：<span style="color: red">{{ row.dataExtMap.unit }}</span></span>
                </div>
              </div>
            </template>
            <template v-if="row.fieldType === '3'">
              <div style="display: inline-flex">
                <span style="width: 100px">0：<span style="color: red">{{ row.dataExtMap.falseValue }}</span></span>
                <span>1：<span style="color: red">{{ row.dataExtMap.trueValue }}</span></span>
              </div>
            </template>
            <template v-if="row.fieldType === '4'">
              <div v-for="item in row.dataExtMap.enumList">
                <div style="display: inline-flex">
                  <span style="width: 100px">名称：<span style="color: red">{{ item. label}}</span></span>
                  <span>值： <span style="color: red">{{ item.value}}</span></span>
                </div>
              </div>
            </template>
            <template v-if="row.fieldType === '5'">
              <div>最大长度：<span style="color: red">{{ row.dataExtMap.maxLength }}</span></div>
            </template>
            <template v-if="row.fieldType === '6'">
              <div>元素个数：<span style="color: red">{{ row.dataExtMap.arrayLength }}</span></div>
            </template>
            <template v-if="row.fieldType === '7'">

            </template>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
